﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Geometry
{
    public class QuadraticSolving
    {
        public double a { get; private set; }
        public double b { get; private set; }
        public double c { get; private set; }

        public double x1 { get; private set; }//NaN if not set
        public double x2 { get; private set; }//NaN if not set

        public int real_solutions { get; private set; }//-1 if not set

        private double delta;

        public QuadraticSolving(double la, double lb, double lc)
        {
            a = la;
            b = lb;
            c = lc;

            x1 = double.NaN;
            x2 = double.NaN;
            real_solutions = -1;
        }

        private void CalculateDelta()
        {
            delta = Math.Pow(b, 2) - 4 * a * c;
            if (delta < 0) real_solutions = 0;
            if (Math.Round(delta, 5) == 0) real_solutions = 1;
            if (delta > 0) real_solutions = 2;
        }
        public void Calculate()
        {
            CalculateDelta();
            x1 = (-b - Math.Sqrt(delta)) / (2 * a);
            x2 = (-b + Math.Sqrt(delta)) / (2 * a);
        }
    }
}
